<template>
  <div>
    <input style="display: none" type="text" :value="value" />
    <el-select
      allow-create
      default-first-option
      filterable
      v-model="selected"
      :clearable="clearable"
      :placeholder="placeholder"
      :size="size"
      @change="handleItemChange"
    >
      <el-option v-for="(p, key) in this.list" :key="key" :label="p" :value="p"></el-option>
    </el-select>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    value: {
      type: String,
      default: '',
    },
    type: {
      type: String,
      default: 'produce',
    },
    size: {
      type: String,
      default: '',
    },
    placeholder: {
      type: String,
      default: '请输入名称',
    },
    clearable: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      selected: null,
      list: {},
    }
  },
  computed: {},
  watch: {
    value(val) {
      this.selected = val
    },
  },
  created() {
    this.init()
  },
  mounted() {},
  methods: {
    init() {
      this.list = {
        0: '斤',
        1: '公斤',
        2: '头',
        3: '只',
        4: '尾',
        5: '羽',
        6: '亩',
        7: '个',
      }
    },
    handleItemChange(val) {
      if (!this.autoChange) {
        this.$emit('input', val)
        this.$emit('change', this.$utils.findKeyFromValue(this.list, val, '8'))
      }
    },
    getSelected() {
      return this.selected
    },
  },
}
</script>

<style scoped></style>
